﻿using System;
using System.Collections;
using System.Data;
using System.Data.OracleClient;
using INTEX.DataBase.Tools;
public static partial class DAILYMORNING
{
    public static DateTime tomorrow = DateTime.Now.AddDays(1);
    public static DateTime yesterday = DateTime.Now.AddDays(-1);
    public static string today = "";
    public static string Right(string str, int num)
    {
        try
        {
            int leng = str.Length;
            str = str.Substring(leng - num, num);
        }
        catch (Exception ex)
        {
        }
        return str;
    }
    public static string Left(string str, int num)
    {
        try
        {
            int leng = str.Length;
            str = str + "                                                                                ";
            str = str.Substring(0, num);
        }
        catch (Exception ex)
        {

        }
        return str;
    }
    public static void Upload(DataSet setnotify)
    {
        string file = @"C:\IntexReport\PhoneDB\BatchLoadIntexKeyTable.TOSKY";
        setnotify.WriteXml(file, XmlWriteMode.IgnoreSchema);
 
    }
    public static DataSet GetSkyDriveFileList()
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        try
        {
            string file = @"C:\IntexReport\PhoneDB\SkyFileList.xml";
            if (!System.IO.File.Exists(file))
            {
                //通常会存在
                ReadSkydrive();
            }
            result.ReadXml(file);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        { 
        }
        return setreturn;
    }
    private static void ReadSkydrive()
    {
        try
        {
            DataSet setnotify = new DataSet();
            string file = @"C:\IntexReport\PhoneDB\ReadSkydrive.TOSKY";
            setnotify.WriteXml(file, XmlWriteMode.IgnoreSchema);
        }
        catch (Exception ex)
        { 
        }
    }
    public static DataSet BatchLoadIntexKeyTable(string option="LE")
    { 
        today=yesterday.Year.ToString()+Right("00"+yesterday.Month.ToString(),2)+Right("00"+yesterday.Day.ToString(),2);
        //option is used to get batch data EQ(equal) to today to  LE(less equal) today
        //if request by phone, usuallly it is LE
        //locally, every day can prepare the data by EQ
        OracleCommand cmd = new OracleCommand();
        cmd.CommandType = CommandType.Text;
        cmd.Connection = new OracleConnection("user id=intex;data source=intex1;password=intex;Unicode=True;Persist Security Info=True;");
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        try
        {            
            /*result = ReadKDSTAMM(cmd);
            result = ReadVAART(cmd);
            result = ReadVAFARBEN(cmd);
            result = ReadWBDAT(cmd);
            result = ReadGPBST(cmd);            
            result = ReadVKPOS(cmd);
            result = ReadVKKOPF(cmd);            
            result = ReadWASTAMM(cmd);
            result = ReadWAFARBEN(cmd);
            result = ReadWDECK(cmd);
            result = ReadABAUFM(cmd);
            result = ReadABPOS(cmd);
            result = ReadABFOLGE(cmd);
            result = ReadBAAUF(cmd);
            result = ReadGAAUF(cmd);
            result = ReadGSDAT(cmd);
            result = ReadGSCOLOR(cmd);
            result = ReadLIEFDAT(cmd); */
            result = ReadWASTAMM(cmd,"EQ");
            setreturn.Merge(result);
            Upload(new DataSet());
            /* 
             * */
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadGPBST(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "GPBST";
        try
        {
            cmd.CommandText = "SELECT GPBMANDANT,GPBPARTIE,GPBART,GPBVAR,GPBFARBE,GPBBSTKGG FROM GPBST WHERE GPBMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText +=" AND (GPBNEUDAT>=" + today + " OR GPBAENDDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("GPBMANDANT");
            keylist.Add("GPBPARTIE");
            keylist.Add("GPBART");
            keylist.Add("GPBVAR");
            keylist.Add("GPBFARBE"); 
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex) { }
        return setreturn;
    }
    private static DataSet ReadWBDAT(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "WBDAT";
        try
        {
            cmd.CommandText = "SELECT WBMANDANT,WBWAKZ,WBART,WBVAR,WBCOLORIT,WBFARBE,WBBESCHICH,WBZUSTAND,WBSTK,WBMTR FROM WBDAT WHERE WBMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText  +=" AND (WBAENDDAT>=" + today + " OR WBNEUDAT>=" + today + ")";
            }
            //WBAENDDAT,WBNEUDAT
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("WBMANDANT");
            keylist.Add("WBWAKZ");
            keylist.Add("WBART");
            keylist.Add("WBVAR");
            keylist.Add("WBCOLORIT");
            keylist.Add("WBFARBE");
            keylist.Add("WBBESCHICH");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex) { }
        return setreturn;
    }
    private static DataSet ReadVAFARBEN(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "VAFARBEN";
        try
        {
            cmd.CommandText = "SELECT VAFMANDANT,VAFKOLL,VAFART,VAFFARBE,VAFBEZ,VAFFFARBE,VAFCOLORIT,VAFBESCHICH FROM VAFARBEN WHERE VAFMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText += " AND (VAFAENDDAT>=" + today + " OR VAFNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("VAFMANDANT");
            keylist.Add("VAFKOLL");
            keylist.Add("VAFART");
            keylist.Add("VAFFARBE");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex)        {        }
        return setreturn;
    }
    private static DataSet ReadVAART(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "VAART";
        try
        {
            cmd.CommandText = "SELECT VAAMANDANT,VAAKOLL,VAAART,VAABEZ,VAABRTVON,VAAMEBRT,VAADART,VAADVAR FROM VAART WHERE VAAMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText += " AND (VAAAENDDAT>=" + today + " OR VAANEUDAT>=" + today + ")";
            }
            //VAAAENDDAT,VAANEUDAT
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("VAAMANDANT");
            keylist.Add("VAAKOLL");
            keylist.Add("VAAART");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadKDSTAMM(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "KDSTAMM";
        try
        {
            cmd.CommandText = "SELECT KDMANDANT,KDKUNDNR,KDKUNDNA,KDABCKL,KDNAME1,"
                + "KDKNAME,KDNAME2,KDSTRASSE1,KDSTRASSE2,KDTEL,KDMAILADR FROM KDSTAMM WHERE KDMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText+=" AND (KDAEND>=" + today + " OR KDNEUD>=" + today + ")";
            }
            //KDAEND,KDNEUD
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("KDMANDANT");
            keylist.Add("KDKUNDNR");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadVKPOS(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "VKPOS";
        try
        {
            cmd.CommandText = " SELECT VKPMANDANT,VKPAUFKRS, VKPAUFLFD,VKPAUFPOS," +
                    "VKPNEUDAT,VKPKUNDNR"
                    + ",VKPART,VKPFARBE,VKPMENGE1,VKPMENGE2,VKPRESERV,VKPZUGET,VKPFREIGE,VKPGAUFBEST,VKPKOMMISS"
                    + ",VKPFAKT,VKPVERS,VKPEINGET,VKPOFFEN,VKPMEEH"
                    + ", VKPLIEFTERM"
                    + " FROM VKPOS WHERE VKPMANDANT='00' AND VKPSA<>'AJ' ";

            if (option == "EQ")
            {
                cmd.CommandText += " AND (VKPNEUDAT>=" + today + " OR VKPPAENDDAT>=" + today + ")";
            }
            //VKPNEUDAT,VKPPAENDDAT
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("VKPMANDANT");
            keylist.Add("VKPAUFKRS");
            keylist.Add("VKPAUFLFD");
            keylist.Add("VKPAUFPOS");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadVKKOPF(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "VKKOPF";
        try
        {
            cmd.CommandText = "select VKKMANDANT,VKKAUFKRS,VKKAUFLFD,VKKNEUDAT,VKKKUNDNR,VKKSACHBE "
                +"from VKKOPF WHERE   VKKMANDANT='00' ";
            if (option == "EQ")
            {
                //VKKAENDDAT,VKKNEUDAT
                cmd.CommandText += " AND (VKKAENDDAT>=" + today + " OR VKKNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("VKKMANDANT");
            keylist.Add("VKKAUFKRS");
            keylist.Add("VKKAUFLFD");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadWASTAMM(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "WASTAMM";
        try
        {
            cmd.CommandText = "SELECT WAMANDANT,WAART,WAVAR,WANEUB,WANEUD,WABEZ,WAFDDIM,WARWBRT,"
            +"WARGRQM,WARFDDIK,WARFDDIS,WABIND,WAFGRLFD,WAFFDDIK,WAFFDDIS"+
                " FROM WASTAMM WHERE WAMANDANT='00'";

            if (option == "EQ")
            {
                // WAAEND,WANEUD 
                cmd.CommandText += " AND (WAAEND>=" + today + " OR WANEUD>=" + today + ")";
            }


            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("WAMANDANT");
            keylist.Add("WAART");
            keylist.Add("WAVAR");
            DataToXml.Convert2XML("PhoneDB",result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadWAFARBEN(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "WAFARBEN";
        try
        {
            cmd.CommandText = "SELECT WAFMANDANT,WAFART,WAFVAR,WAFZUART,WAFZUSATZ,WAFBEZ FROM WAFARBEN WHERE WAFMANDANT='00'";


            if (option == "EQ")
            {
                // WAFAENDDAT,WAFNEUDAT
                cmd.CommandText += " AND (WAFAENDDAT>=" + today + " OR WAFNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("WAFMANDANT");
            keylist.Add("WAFART");
            keylist.Add("WAFVAR");
            keylist.Add("WAFZUART");
            keylist.Add("WAFZUSATZ");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadWDECK(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "WDECK";
        try
        {
            //SELECT WDSA,WDAUFKRS,WDAUFLFD,WDAUFPOS,WDTYP,WDUPOS,WDWAKZ,WDART,WDDESS,WDCOLORIT,WDFARBE,WDBESCHICH,WDVAR,WDDAT,WDPRART,WDPRVAR FROM WDECK WHERE WDMANDANT='00'
            cmd.CommandText = "SELECT WDMANDANT,WDSA,WDAUFKRS,WDAUFLFD,WDAUFPOS,WDTYP,WDUPOS,"
            +"WDWAKZ,WDART,WDDESS,WDCOLORIT,WDFARBE,WDBESCHICH,WDVAR,WDDAT,WDPRART,WDPRVAR "
            +" FROM WDECK WHERE WDMANDANT='00'";

            if (option == "EQ")
            {
                // WAFAENDDAT,WAFNEUDAT
                //cmd.CommandText += " AND (WAFAENDDAT>=" + today + " OR WAFNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("WDMANDANT");
            keylist.Add("WDSA");
            keylist.Add("WDAUFKRS");
            keylist.Add("WDAUFLFD");
            keylist.Add("WDAUFPOS");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadABAUFM(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "ABAUFM";
        try
        {
            //SELECT ABAAUFTYP,ABAAUFKRS,ABAAUFLFD,ABAAUFPOS,ABAAPOS,ABAVKAUFTYP,ABAVKAUFKRS,ABAVKAUFLFD,ABAVKAUFPOS,ABAVKUPOS,ABAKUNDNR FROM ABAUFM WHERE ABAMANDANT='00'
            cmd.CommandText = "SELECT ABAMANDANT,ABAAUFTYP,ABAAUFKRS,ABAAUFLFD,ABAAUFPOS,ABAAPOS,ABAVKAUFTYP," +
                "ABAVKAUFKRS,ABAVKAUFLFD,ABAVKAUFPOS,ABAVKUPOS,ABAKUNDNR"
                +" FROM ABAUFM WHERE ABAMANDANT='00'";

            if (option == "EQ")
            {
                // ABAAENDDAT,ABANEUDAT
                cmd.CommandText += " AND (ABAAENDDAT>=" + today + " OR ABANEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("ABAMANDANT");
            keylist.Add("ABAAUFTYP");
            keylist.Add("ABAAUFKRS");
            keylist.Add("ABAAUFLFD");
            keylist.Add("ABAAUFPOS");
            keylist.Add("ABAAPOS");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadABPOS(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "ABPOS";
        try
        {
            //SELECT ABAAUFTYP,ABAAUFKRS,ABAAUFLFD,ABAAUFPOS,ABAAPOS,ABAVKAUFTYP,ABAVKAUFKRS,ABAVKAUFLFD,ABAVKAUFPOS,ABAVKUPOS,ABAKUNDNR FROM ABAUFM WHERE ABAMANDANT='00'
            cmd.CommandText = "SELECT ABPMANDANT,ABPAUFKRS,ABPAUFLFD,ABPAUFPOS,ABPWAKZ,ABPART,ABPVAR,ABPFARBE,ABPSOLLMENGE1,ABPSOLLMENGE2,ABPSOLLMENGE3,ABPSOLLMENGE4,ABPSOLLMENGE5,ABPSOLLMENGE6,ABPSOLLMENGE7,ABPSOLLMENGE8," +
                "ABPLIEFDAT,ABPSTARTDAT, ABPNEUDAT FROM ABPOS WHERE ABPMANDANT='00'";

            if (option == "EQ")
            {
                // ABPAENDDAT,ABPNEUDAT
                cmd.CommandText += " AND (ABPAENDDAT>=" + today + " OR ABPNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("ABPMANDANT");
            keylist.Add("ABPAUFKRS");
            keylist.Add("ABPAUFLFD");
            keylist.Add("ABPAUFPOS");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadABFOLGE(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "ABFOLGE";
        try
        {
            //SELECT ABFAUFKRS,ABFAUFLFD,ABFAUFPOS,ABFAFOLGE,ABFAGANG,ABFBZAGANG,ABFSOLLSTART,ABFSOLLDAT FROM ABFOLGE WHERE ABFMANDANT='00'
            cmd.CommandText = "SELECT ABFMANDANT,ABFAUFKRS,ABFAUFLFD,ABFAUFPOS,ABFAFOLGE,ABFAGANG,ABFBZAGANG,ABFSOLLSTART,ABFSOLLDAT " +
                " FROM ABFOLGE WHERE ABFMANDANT='00'";
            if (option == "EQ")
            {
                // ABPAENDDAT,ABPNEUDAT
                cmd.CommandText += " AND (ABFAENDDAT>=" + today + " OR ABFNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("ABFMANDANT");
            keylist.Add("ABFAUFKRS");
            keylist.Add("ABFAUFLFD");
            keylist.Add("ABFAUFPOS");
            keylist.Add("ABFAFOLGE");

            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadBAAUF(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "BAAUF";
        try
        {
            //SELECT BAAUFTYP,BAAUFKRS,BAAUFLFD,BAAUFPOS,BASA,BAPOS,BAAFOLGE,BADATVON,BAKART,BAKVAR,BAKFARBE
//,BAMTR1,BAANZ1,BAMTR2,BAANZ2,BAMTR3,BAANZ3,BAMTR4,BAANZ4,BAMTR5,BAANZ5,BAMTR6,BAANZ6 ,BAMTR7,BAANZ7 FROM BAAUF WHERE BAMANDANT='00'
            cmd.CommandText = "SELECT BAMANDANT,BAAUFTYP,BAAUFKRS,BAAUFLFD,BAAUFPOS,BASA,BAPOS,BAAFOLGE,BADATVON,BAKART,BAKVAR,BAKFARBE"
                +",BAMTR1,BAANZ1,BAMTR2,BAANZ2,BAMTR3,BAANZ3,BAMTR4,BAANZ4,BAMTR5,BAANZ5,BAMTR6,BAANZ6 ,BAMTR7,BAANZ7 "+
                " FROM BAAUF WHERE BAMANDANT='00'";

            if (option == "EQ")
            {
                cmd.CommandText += " AND (BAAENDDAT>=" + today + " OR BANEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            keylist.Add("BAMANDANT");
            keylist.Add("BAAUFKRS");
            keylist.Add("BAAUFLFD");
            keylist.Add("BAAUFPOS");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadGAAUF(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "GAAUF";
        try
        {
            //SELECT GAAUFKRS,GAAUFLFD,GAAUFPOS,GASA,GAPOS,GAART,GAVAR,GAFARBE,GAKG1,GAKG2,GAKG3,GAKG4,GAKG5,GAKG6,GAKG7 FROM GAAUF WHERE GAMANDANT='00'
            cmd.CommandText = "SELECT GAMANDANT,GAAUFKRS,GAAUFLFD,GAAUFPOS,GASA,GAPOS,GAART,GAVAR,GAFARBE"
            +",GAKG1,GAKG2,GAKG3,GAKG4,GAKG5,GAKG6,GAKG7"
                +"  FROM GAAUF WHERE GAMANDANT='00'";

            if (option == "EQ")
            {
                cmd.CommandText += " AND (GAAENDDAT>=" + today + " OR GANEUDAT>=" + today + ")";
            }

            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            // GAMANDANT,GAAUFKRS,GAAUFLFD,GAAUFPOS,GASA,GAPOS
            keylist.Add("GAMANDANT");
            keylist.Add("GAAUFKRS");
            keylist.Add("GAAUFLFD");
            keylist.Add("GAAUFPOS");
            keylist.Add("GASA");
            keylist.Add("GAPOS");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);
            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadGSDAT(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "GSDAT";
        try
        {
            //SELECT GSART,GSVAR,GSHANDLNR,GSGARNBEZ,GSNUMART,GSGARNNR,GSFACH,GSRECHNUM,GSRECHNR FROM GSDAT WHERE GSMANDANT='00'
            cmd.CommandText = "SELECT GSMANDANT,GSART,GSVAR,GSHANDLNR,GSGARNBEZ,GSNUMART"
            +",GSGARNNR,GSFACH,GSRECHNUM,GSRECHNR FROM GSDAT WHERE GSMANDANT='00'";

            if (option == "EQ")
            {
                cmd.CommandText += " AND (GSAENDDAT>=" + today + " OR GSNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            // GAMANDANT,GAAUFKRS,GAAUFLFD,GAAUFPOS,GASA,GAPOS
            keylist.Add("GSMANDANT");
            keylist.Add("GSART");
            keylist.Add("GSVAR");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadGSCOLOR(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "GSCOLOR";
        try
        {
            //SELECT GSCART,GSCVAR,GSCFARBE, GSCBEZ FROM GSCOLOR WHERE GSCMANDANT='00'
            cmd.CommandText = "SELECT GSCMANDANT,GSCART,GSCVAR,GSCFARBE, GSCBEZ "
            +" FROM GSCOLOR WHERE GSCMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText += " AND (GSCAENDDAT>=" + today + " OR GSCNEUDAT>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            // GAMANDANT,GAAUFKRS,GAAUFLFD,GAAUFPOS,GASA,GAPOS
            keylist.Add("GSCMANDANT");
            keylist.Add("GSCART");
            keylist.Add("GSCVAR");
            keylist.Add("GSCFARBE");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static DataSet ReadLIEFDAT(OracleCommand cmd, string option = "LE")
    {
        DataSet result = new DataSet();
        DataSet setreturn = new DataSet();
        string table = "LIEFDAT";
        try
        {
            //S LSAEND,LSNEUD 
            cmd.CommandText = "SELECT LSMANDANT,LSLIEFNR,LSLIEFNA,LSNAME1,LSNAME2,LSSTRASSE1,LSLAND,LSPLZ,LSORT,LSTELEX,LSMAILADR "
            +" FROM LIEFDAT WHERE LSMANDANT='00'";
            if (option == "EQ")
            {
                cmd.CommandText += " AND (LSAEND>=" + today + " OR LSNEUD>=" + today + ")";
            }
            OracleDataAdapter myDa = new OracleDataAdapter(cmd);
            myDa.Fill(result);
            if (result.Tables.Count > 0)
            {
                result.Tables[0].TableName = table;
            }
            string key = table;
            ArrayList keylist = new ArrayList();
            // GAMANDANT,GAAUFKRS,GAAUFLFD,GAAUFPOS,GASA,GAPOS
            keylist.Add("LSMANDANT");
            keylist.Add("LSLIEFNR");
            DataToXml.Convert2XML("PhoneDB", result.Tables[0], key, keylist);

            setreturn.Merge(result);
        }
        catch (Exception ex)
        {
        }
        return setreturn;
    }
    private static void StartUpload()
    {
        try
        { 
        }
        catch (Exception ex)
        { 

        }
    }
    //SELECT LSLIEFNR,LSLIEFNA,LSNAME1,LSNAME2,LSSTRASSE1,LSLAND,LSPLZ,LSORT,LSTELEX,LSMAILADR FROM LIEFDAT WHERE LSMANDANT='00'
}
 